<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>画一个立方体</title>
    <style>

        body {
            perspective: 800px; /*关键，指定透视距离，才能有立体感*/
            /* perspective-origin: 50% 0px; */
            height: 100vh;
            background-color: aliceblue;

            display: flex;
            justify-content: center;
            align-items: center;
            overflow: hidden;
        }

        .cube {
            --size: 200px;  /*控制立方体的大小*/

            position: relative;
            width: var(--size);
            height: var(--size);
            transform-style: preserve-3d;
            font-size: 60px;
            text-align: center;
            line-height: var(--size);

            transform: rotateX(-30deg) rotateY(-30deg) rotateZ(0deg);

            --move1: calc(var(--size)/2);
            --move2: calc(var(--size)/-2);
            --rotate: 90deg;
            
        }

        .cube div {
            position: absolute;
            width: 100%;
            height: 100%;

            box-shadow: 0 0 19px rgba(63, 81, 181, 0.21);
            font-size: 30px;
            text-align: center;
            line-height: var(--size);
            color: rgba(255, 255, 255, 0.78);
        }

        .front {
            transform: translateZ(var(--move1));
            background-color: rgba(170, 0, 212, 0.78);
        }
        .back {
            transform: translateZ(var(--move2));
            background-color: rgba(0, 188, 212, 0.78);
        }

        .right {
            transform: rotateY(var(--rotate)) translateZ(var(--move1));
            background-color: rgba(212, 191, 0, 0.78);
        }
        .left {
            transform: rotateY(var(--rotate)) translateZ(var(--move2));
            background-color: rgba(25, 22, 202, 0.78);
        }

        .top {
            transform: rotateX(var(--rotate)) translateZ(var(--move1));
            background-color: rgba(0, 212, 95, 0.78);
        }
        .bottom {
            transform: rotateX(var(--rotate)) translateZ(var(--move2));
            background-color: rgba(158, 158, 158, 0.78);
        }


        .cube .line {
            width: 1000px;
            border-bottom: 1px dashed #00000091;
            height: 0px;
            top: 100%;
            left: 50%;

        }

        .line-y{
            transform: rotateZ(-90deg);
            transform-origin: left;
        }

        .line-z{
            transform: rotatey(-90deg);
            transform-origin: left;
        }
    </style>
</head>

<body>

        <div class="cube">
            <div class="front">前</div>
            <div class="back">后</div>
            <div class="top">上</div>
            <div class="bottom">下</div>
            <div class="left">左</div>
            <div class="right">右</div>

            <div class="line line-x"></div>
            <div class="line line-y"></div>
            <div class="line line-z"></div>
        </div>



</body>

</html>